package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"renting-demo/api/internal/config"
	"renting-demo/api/internal/middleware"
	"renting-demo/cart_srv/cartclient"
	"renting-demo/goods_srv/goodsclient"
	"renting-demo/house_srv/houseclient"
	"renting-demo/houseorder_srv/houseorderclient"
	"renting-demo/order_srv/orderclient"
	"renting-demo/user_srv/userclient"
)

type ServiceContext struct {
	Config           config.Config
	AuthToken        rest.Middleware
	UserServer       userclient.User
	GoodsServer      goodsclient.Goods
	CartServer       cartclient.Cart
	OrderServer      orderclient.Order
	HouseServe       houseclient.House
	HouseOrderServer houseorderclient.Houseorder
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:           c,
		AuthToken:        middleware.NewAuthTokenMiddleware().Handle,
		UserServer:       userclient.NewUser(zrpc.MustNewClient(c.UserServer)),
		GoodsServer:      goodsclient.NewGoods(zrpc.MustNewClient(c.GoodsServer)),
		CartServer:       cartclient.NewCart(zrpc.MustNewClient(c.CartServer)),
		OrderServer:      orderclient.NewOrder(zrpc.MustNewClient(c.OrderServer)),
		HouseServe:       houseclient.NewHouse(zrpc.MustNewClient(c.HouseServe)),
		HouseOrderServer: houseorderclient.NewHouseorder(zrpc.MustNewClient(c.HouseOrderServer)),
	}
}
